package com.ikingtech.platform.service.application.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikingtech.framework.sdk.application.model.ApplicationPageQueryParamDTO;
import com.ikingtech.framework.sdk.base.model.PageResult;
import com.ikingtech.framework.sdk.utils.Tools;
import com.ikingtech.platform.service.application.entity.ApplicationPageDO;
import com.ikingtech.platform.service.application.mapper.ApplicationPageMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tie yan
 */
@Service
public class ApplicationPageService extends ServiceImpl<ApplicationPageMapper, ApplicationPageDO> {

    public List<ApplicationPageDO> listByAppId(String appId) {
        return this.list(Wrappers.<ApplicationPageDO>lambdaQuery().eq(ApplicationPageDO::getAppId, appId));
    }

    public PageResult<ApplicationPageDO> listPage(ApplicationPageQueryParamDTO queryParam) {
        return PageResult.build(this.page(new Page<>(queryParam.getPage(), queryParam.getRows()), Wrappers.<ApplicationPageDO>lambdaQuery()
                .eq(Tools.Str.isNotBlank(queryParam.getAppCode()), ApplicationPageDO::getAppCode, queryParam.getAppCode())
                .like(Tools.Str.isNotBlank(queryParam.getName()), ApplicationPageDO::getName, queryParam.getName())
                .eq(Tools.Str.isNotBlank(queryParam.getType()), ApplicationPageDO::getType, queryParam.getType())));
    }

    public boolean exist(String id) {
        return this.baseMapper.exists(Wrappers.<ApplicationPageDO>lambdaQuery().eq(ApplicationPageDO::getId, id));
    }
}
